/**Class represents a geometric triangle.
 * 
 */
public class Triangle implements Polygon {
	private double a;
	private double b;
	private double c;
	
	/**Creates a new triangle with the given lengths for each of the edges.
	 * 
	 * @param a Length of first edge.
	 * @param b Length of second edge.
	 * @param c Length of third edge.
	 * @throws ValueSmallerZeroException Exception if negative values are given for the length of an edge.
	 */
	public Triangle(double a, double b, double c) throws ValueSmallerZeroException {
		if(a > 0) {
			this.a = a;
		} else {
			throw new ValueSmallerZeroException(a);
		}
		if(b > 0) {
			this.b = b;
		} else {
			throw new ValueSmallerZeroException(b);
		}
		if(c > 0) {
			this.c = c;
		} else {
			throw new ValueSmallerZeroException(c);
		}
	}
	
	/**Changes the length of the first edge to the given length.
	 * 
	 * @param a Double value given for the new length of the edge.
	 * @throws ValueSmallerZeroException Exception if negative values are given for the length an edge.
	 */
	public void setA(double a) throws ValueSmallerZeroException{
		if(a > 0) {
			this.a = a;
		} else {
			throw new ValueSmallerZeroException(a);
		}
	}
	
	/**Changes the length of the second edge to the given length.
	 * 
	 * @param a Double value given for the new length of the edge.
	 * @throws ValueSmallerZeroException Exception if negative values are given for the length of an edge.
	 */
	public void setB(double b) throws ValueSmallerZeroException{
		if(b > 0) {
			this.b = b;
		} else {
			throw new ValueSmallerZeroException(b);
		}
	}
	
	/**Changes the length of the third edge to the given length.
	 * 
	 * @param a Double value given for the new length of the edge.
	 * @throws ValueSmallerZeroException Exception if negative values are given for the length of an edge.
	 */
	public void setC(double c) throws ValueSmallerZeroException{
		if(c > 0) {
			this.c = c;
		} else {
			throw new ValueSmallerZeroException(c);
		}
	}
	
	/**Returns the number of edges.
	 * 
	 * @return Integer value 3 since triangle has 3 edges.
	 */
	@Override
	public int edges() {
		return 3;
	}

	/**Returns the size of the area the specified triangle takes in.
	 * 
	 * @return By Heron's formula calculated double value of area.
	 */
	@Override
	public double area() {
		double s = (this.a + this.b + this.c)/2;
		return Math.sqrt(s * (s-this.a) * (s-this.b) * (s-this.c));
	}

	/**Calculates the size of the outline the specified triangle takes in.
	 * 
	 * @return Calculated double value of the outline.
	 */
	@Override
	public double perimeter() {
		return this.a + this.b + this.c;
	}
	
}
